using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows;

public class GlobalData : MonoBehaviour
{
    private static GlobalData instance;
    private Dictionary<string, int> intDictionary = new Dictionary<string, int>();

    [RuntimeInitializeOnLoadMethod]
    private static void  Init()
    {
        if (instance == null)
        {
            GameObject go = new GameObject("GlobalData");
            DontDestroyOnLoad(go);//阻止Scene切换时，object销毁
            instance = go.AddComponent<GlobalData>();
        }
    }
    //保存数据
    public static void SetInt(string key,int val)
    {
        if (instance.intDictionary.ContainsKey(key))
            instance.intDictionary[key] = val;
        else
            instance.intDictionary.Add(key, val);
    }
    //取出数据
    public static int GetInt(string key, int defaultVal = 0)
    {
        if (instance.intDictionary.ContainsKey(key))
            return instance.intDictionary[key];
        else
            return defaultVal;
    }
}
